<template>
	<view class="campus-content">
		<view class="campus-swiper">
			<!-- @click="joinSchool" -->
			<!-- <image src="../../static/imgs/campus/swiper3.png" class="campus-swiper-img"
			 ></image> -->
			 <view class="noschool_header" v-if="isStudent=='false'" @click="games">
				<image :src="sport.thumb"></image>
				<view class="noschool_button">
					<image mode="widthFix" src="../../static/imgs/games/noschool-bg.png"></image>
				</view>
			 </view>
			<swiper v-else class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay"
				:interval="interval" :duration="duration" :style="{height: `${Height} `}">
				<swiper-item v-for="(item,index) in studentInfo.banners" :key="index">
					<image :src="item.img" mode="widthFix" @load="imgHeight" @click="swiperHref(item)"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="campus-school" v-if="isStudent=='true'">
			<view class="campus-school_name text_black">{{studentInfo.school_name}}</view>
			<view class="campus-school_href text_opblack" @click="goList(1)">
				校园动态
				<image src="../../static/imgs/mine/right.png"></image>
			</view>
		</view>
		<view class="campus-student" v-if="isStudent=='true'">
			<image src="../../static/imgs/campus/stydent-icon.png" class="campus-student_icon"></image>
			<view style="width: 100%;">
				<view class="campus-student_name text_black">
					{{studentInfo.student_name}}
				</view>
				<view class="campus-student_msg text_opblack">
					<text class="campus-student_msg_schoolName">{{studentInfo.school_name}}</text>
					<text>{{studentInfo.class_name}}</text>
					<text>{{studentInfo.student_gender=='1'?'男':'女'}}</text>
					<text class="last-text" v-if="studentInfo.teacher_name">体育老师 {{studentInfo.teacher_name}}</text>
				</view>
			</view>
		</view>
		<view class="school-sport" v-if="isStudent=='true'" @click="games">
			<image src="../../static/imgs/campus/soprt.png"></image>
		</view>
		<!-- <view class="campus-data">
			<view class="campus-title text_opblack">体测数据</view>
			<view class="campus-data-list">
				<view class="campus-data-item" v-for="(item,index) in datas" :key="index">
					<view class="campus-data-item_icon" :style="{backgroundColor:item.bgcolor,color:item.color}">待定
					</view>
					<view class="text_black">{{item.name}}</view>
				</view>
			</view>
		</view> -->
		<view class="campus-type" :style="{marginTop:isStudent=='true'?'0':'10rpx'}">
			<view class="campus-type-item" v-for="(item,index) in typeList" :key="index" @click="typeHref(item)">
				<image :src="item.icon"></image>
				<view>{{item.name}}</view>
			</view>
		</view>
		<view class="campus-plan" v-if="isStudent=='true'">
			<view class="campus-title text_black">本校优秀作业</view>
			<view class="campus-tips text_opblack">恭喜以下同学的体能训练作业非常优秀，排名不分先后。</view>
			<view class="campus-plan-list">
				<view class="campus-plan-item" v-for="(item,index) in planList" :key="index" @click="planItem(item)">
					<view>
						<view class="text_black campus-plan-item-name">{{item.name}}</view>
						<view class="text_opblack campus-plan-item-tips">{{item.class_name}} {{item.title}}</view>
					</view>
					<view class="campus-plan-item-href text_opblack">
						观看学习
						<image src="../../static/imgs/mine/right.png"></image>
					</view>
				</view>
			</view>
		</view>
		<view v-if="isStudent=='false'" class="campus-noIsDtudent">
			<view class="text_black">温馨提示</view>
			<view class="text_opblack" style="text-indent: 2em">
				     您好！您目前暂未接入学校校园体能，希望您推荐到您孩子的学校。学校接入后您孩子会学习到：幼儿园、小学、初中、中考体育”全阶段的体能课程。您还会了解到孩子的身体健康数据指标和体能体测数据以及学生周期体能训练计划。您孩子使用后更会让您和孩子体会到家校联动的体育训练带来的乐趣和重要性。</view>
		</view>
		<!-- <view v-if="isStudent=='false'" clas s="campus-noIsDtudent">
			<view class="text_black">您目前暂未接入校园体能</view>
			<view class="text_opblack">
				接入后限时免费使用智能体测设备；学习从”幼儿园到体考”阶段全面的体能课程。涵盖从“幼儿园到体考”全部阶段的体能指标训练，并全面提升学生的体能素质，增加抵抗力，强身健体。</view>
		</view> -->
	</view>
</template>

<script>
	import {getSportIndex} from "../../static/js/api/games.js";
	import {getSchoolIndex,getSchoolDetail,getSchoolBanner} from "../../static/js/api/plan.js"
	export default {
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 5000,
				duration: 500,
				isStudent: 1, //0为无合作 1有合作
				controls: false,
				showPlan: false,
				datas: [{
					name: "形体判定",
					bgcolor: "#E5FAFF",
					color: "#00CEFF",
				}, {
					name: "平衡能力",
					bgcolor: "#FFF4E8",
					color: "#FF8500",
				}, {
					name: "基础代谢",
					bgcolor: "#FFF5F1",
					color: "#E85F5F",
				}, {
					name: "心肺功能",
					bgcolor: "#F4FFE1",
					color: "#8FC335",
				}, ],
				typeList: [{
					href: "/pages/basicCourse/index",
					icon: require("../../static/imgs/campus/type_01.png"),
					name: "基础课程"
				}, {
					href: "/pages/plan/list",
					icon: require("../../static/imgs/campus/type_02.png"),
					name: "训练计划"
				}, {
					href: "/pages/campus/list?type=4",
					icon: require("../../static/imgs/campus/type_03.png"),
					name: "示范教学"
				}, {
					href: "/pages/campus/sportsTesting",
					icon: require("../../static/imgs/campus/type_04.png"),
					name: "体测荣誉"
				}, {
					href: "/pages/campus/list?type=2",
					icon: require("../../static/imgs/campus/type_06.png"),
					name: "校园活动"
				}, {
					href: "/pages/campus/list?type=3",
					icon: require("../../static/imgs/campus/type_05.png"),
					name: "教育讲坛"
				}],
				planList: [
				// 	{
				// 	name: "引体向上...",
				// 	video: require('../../static/imgs/campus/video.mp4')
				// }, {
				// 	name: "引体向上...",
				// 	video: require('../../static/imgs/campus/video.mp4')
				// }, {
				// 	name: "引体向上...",
				// 	video: require('../../static/imgs/campus/video.mp4')
				// }, {
				// 	name: "引体向上...",
				// 	video: require('../../static/imgs/campus/video.mp4')
				// }, {
				// 	name: "引体向上...",
				// 	video: require('../../static/imgs/campus/video.mp4')
				// }, {
				// 	name: "引体向上...",
				// 	video: require('../../static/imgs/campus/video.mp4')
				// },
				],
				studentInfo:{},
				student_id:206,
				Height:0,
				sport:{},
			}
		},
		onLoad(option) {
			if (option.studentInfo) {
				let studentInfo = JSON.parse(option.studentInfo)
				console.log(studentInfo)
				this.isStudent = studentInfo.is_bind_school
				this.getSchoolIndex(this.student_id)
			} else {
				this.isStudent = option.school
				this.getSportInfo()
			}
		},
		methods: {
			imgHeight(e) {
				console.log(e)
				var winWid = uni.getSystemInfoSync().windowWidth; //获取当前屏幕的宽度
				var imgh = e.detail.height; //图片高度
				var imgw = e.detail.width; //图片宽度
				var swiperH = winWid * imgh / imgw + "px" //等比设置swiper的高度。 即 屏幕宽度 / swiper高度 = 图片宽度 / 图片高度  ==》swiper高度 = 屏幕宽度 * 图片高度 / 图片宽度
				this.Height = swiperH //设置高度
			},
			getSportInfo(){
				getSportIndex().then(res=>{
					console.log(res)
					this.sport = res.sport
				})
			},
			swiperHref(item){
				// link_type 1不跳转、2外链、3内链
				if (item.link_type == '3') {
					if(item.id=='0'){
						// getSchoolDetail
						uni.navigateTo({
							url: '/pages/campus/schoolDetails?linkUrl='+item.link_url,
						})
					}else{
						// getSchoolBanner
						uni.navigateTo({
							url: '/pages/campus/schoolDetails?bannerId='+item.id,
						})
					}
					
				}
				
			},
			typeHref(item) {
				if (this.isStudent == 'true') {
					if (item.href.length > 0) {
						if(item.name=='训练计划'){
							uni.navigateTo({
								url: '/pages/plan/list?student_id='+this.student_id
							})
						}else if(item.name=='示范教学'||item.name=='校园活动'||item.name=='教育讲坛'){
							uni.navigateTo({
								url: item.href+'&schoolId='+this.studentInfo.school_id
							})
						}else{
							uni.navigateTo({
								url: item.href
							})
						}
					} else {
						uni.showToast({
							title: "暂无功能",
							icon: "none"
						})
					}
				} else {
					if (item.name == '教育讲坛') {
						uni.navigateTo({
							url: item.href+'&schoolId=0'
						})
					} else {
						uni.showToast({
							title: "此功能需接入后使用",
							icon: "none"
						})
					}
				}
			},
			goList(type) {
				uni.navigateTo({
					url: "/pages/campus/list?type=" + type+'&schoolId='+this.studentInfo.school_id
				})
			},
			planItem(item) {
				uni.navigateTo({
					url: "/pages/campus/details?detailsInfo="+JSON.stringify(item)
				})
			},
			// 接入校园
			joinSchool() {
				uni.showToast({
					title: "此功能需接入后使用",
					icon: "none"
				})
				// uni.navigateTo({
				// 	url: "/pages/campus/joinSchool"
				// })
			},
			// 获取本校优秀作业
			getSchoolIndex(id){
				console.log(this.studentInfo)
				getSchoolIndex({
					student_id:id
				}).then(res=>{
					console.log(res)
					this.studentInfo = res.school
					this.planList = res.works
				})
			},
			// 报名运动会
			games(){
				uni.navigateTo({
					url:"/pages/games/application"
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import url("./index.scss");

	.text_opblack {
		color: $uni-text-color-opblack;
	}

	.text_black {
		color: $uni-text-color-black;
	}
	.noschool_button{
		bottom: 30rpx;
	}
</style>